package com.atguigu.flink.chapter05.transform;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.ConnectedStreams;
import org.apache.flink.streaming.api.datastream.DataStreamSink;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.co.CoMapFunction;

/**
 * @author liuyun
 * @title: Flink07_Connect
 * @projectName flink0924
 * @description: TODO
 * @date 2022-3-3 14:34
 */
public class Flink07_Connect {
    public static void main(String[] args) {
        Configuration conf = new Configuration();
        conf.setInteger("rest.port", 20000);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
        env.setParallelism(1);
        DataStreamSource<Integer> stream = env.fromElements(1, 2, 3, 4, 5, 6);

        DataStreamSource<String> stream2 = env.fromElements("a", "b", "c", "d");

        ConnectedStreams<Integer, String> stream3 = stream.connect(stream2);

        stream3.map(new CoMapFunction<Integer, String, String>() {
            @Override
            public String map1(Integer value) throws Exception {
                return value + "<";
            }

            @Override
            public String map2(String value) throws Exception {
                return value + ">";
            }
        }).print();

        try {
            env.execute();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
